home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 101-125 / 118 / empire / src / source.zoo / commands.d < prev    next >
Text File  |  1987-12-02  |  11KB  |  486 lines

  1. #include:libraries/dos.g
  2. #include:util.g
  3. #empire.g
  4. #empfunc.g
  5.  
  6. uint HelpColumn;
  7.  
  8. /*
  9.  * help - print one string as part of the three-column help listing.
  10.  */
  11.  
  12. proc help(*char p)void:
  13.     uint i;
  14.  
  15.     i := 25;
  16.     while p* ~= '\e' do
  17.     write(Chout; p*);
  18.     p := p + 1;
  19.     i := i - 1;
  20.     od;
  21.     HelpColumn := HelpColumn + 1;
  22.     if HelpColumn = 4 then
  23.     writeln(Chout;);
  24.     HelpColumn := 1;
  25.     else
  26.     while i ~= 0 do
  27.         i := i - 1;
  28.         write(Chout; ' ');
  29.     od;
  30.     fi;
  31. corp;
  32.  
  33. /*
  34.  * cmd_help - print a list of currently implemented commands.
  35.  */
  36.  
  37. proc cmd_help()void:
  38.  
  39.     writeln(Chout; "Empire commands are:");
  40.     writeln(Chout;);
  41.     HelpColumn := 1;
  42.     help("accept - 2 BTU's");
  43.     help("assault - 2 BTU's");
  44.     help("attack - 2 BTU's");
  45.     help("board - 2 BTU's");
  46.     help("build - 2 BTU's");
  47.     help("buy - 2 BTU's");
  48.     help("bye");
  49.     help("census");
  50.     help("change");
  51.     help("checkpoint - 2 BTU's");
  52.     help("collect - 2 BTU's");
  53.     help("contract - 2 BTU's");
  54.     help("country");
  55.     help("declare - 2 BTU's");
  56.     help("defend - 2 BTU's");
  57.     help("deliver - 1 BTU");
  58.     help("designate - 1 BTU");
  59.     help("drop - 2 BTU's");
  60.     help("dump");
  61.     help("enlist - 2 BTU's");
  62.     help("fire - 2 BTU's");
  63.     help("fleet - 1 BTU");
  64.     help("fly - 2 BTU's");
  65.     help("forecast - 1 BTU");
  66.     help("grant - 1 BTU");
  67.     help("headlines");
  68.     help("ledger");
  69.     help("lend - 2 BTU's");
  70.     help("load - 2 BTU's");
  71.     help("lookout - 2 BTU's");
  72.     help("map - 1 BTU");
  73.     help("message");
  74.     help("mine - 2 BTU's");
  75.     help("move - 2 BTU's");
  76.     help("nation");
  77.     help("navigate - 2 BTU's");
  78.     help("newspaper");
  79.     help("power");
  80.     help("price - 2 BTU's");
  81.     help("radar - 2 BTU's");
  82.     help("read");
  83.     help("realm");
  84.     help("repay - 2 BTU's");
  85.     help("report - 2 BTU's");
  86.     help("route - 1 BTU");
  87.     help("ships");
  88.     help("spy - 1 BTU");
  89.     help("telegram");
  90.     help("tend - 2 BTU's");
  91.     help("torpedo - 2 BTU's");
  92.     help("unload - 2 BTU's");
  93.     help("update - 1 BTU");
  94.     help("weather");
  95.     if HelpColumn ~= 1 then
  96.     writeln(Chout;);
  97.     fi;
  98. corp;
  99.  
  100. /*
  101.  * chargeCommand - try a command, if user can afford it. Add the BTU's back
  102.  *    if the command returns 'false'.
  103.  */
  104.  
  105. proc chargeCommand(proc()bool command; uint cost)void:
  106.  
  107.     if ThisCountryNumber = DEITY then
  108.     pretend(command(), void);
  109.     else
  110.     if ThisCountry*.c_btu < cost then
  111.         writeln(Chout; "You don't have enough BTU's remaining!");
  112.     else
  113.         ThisCountry*.c_btu := ThisCountry*.c_btu - cost;
  114.         if not command() then
  115.         ThisCountry*.c_btu := ThisCountry*.c_btu + cost;
  116.         fi;
  117.     fi;
  118.     fi;
  119. corp;
  120.  
  121. /*
  122.  * doCommand - attempt to execute the given single command.
  123.  */
  124.  
  125. proc doCommand(uint cmd; *char command)void:
  126.  
  127.     case cmd
  128.     incase 2:
  129.     chargeCommand(cmd_accept, 2);
  130.     incase 3:
  131.     chargeCommand(cmd_assault, 2);
  132.     incase 4:
  133.     chargeCommand(cmd_attack, 2);
  134.     incase 5:
  135.     chargeCommand(cmd_board, 2);
  136.     incase 6:
  137.     chargeCommand(cmd_build, 2);
  138.     incase 8:
  139.     QuietUpdate := false;
  140.     cmd_census();
  141.     incase 9:
  142.     cmd_change();
  143.     incase 10:
  144.     chargeCommand(cmd_checkpoint, 2);
  145.     incase 11:
  146.     chargeCommand(cmd_collect, 2);
  147.     incase 12:
  148.     cmd_help();
  149.     incase 13:
  150.     chargeCommand(cmd_contract, 2);
  151.     incase 14:
  152.     cmd_country();
  153.     incase 15:
  154.     cmd_fleet();
  155.     incase 16:
  156.     chargeCommand(cmd_defend, 2);
  157.     incase 17:
  158.     chargeCommand(cmd_deliver, 1);
  159.     incase 18:
  160.     chargeCommand(cmd_declare, 2);
  161.     incase 19:
  162.     chargeCommand(cmd_designate, 1);
  163.     incase 21:
  164.     chargeCommand(cmd_enlist, 2);
  165.     incase 22:
  166.     chargeCommand(cmd_buy, 2);
  167.     incase 23:
  168.     chargeCommand(cmd_fire, 2);
  169.     incase 24:
  170.     chargeCommand(cmd_fly, 2);
  171.     incase 25:
  172.     chargeCommand(cmd_forecast, 1);
  173.     incase 26:
  174.     chargeCommand(cmd_grant, 1);
  175.     incase 27:
  176.     cmd_headlines();
  177.     incase 28:
  178.     cmd_help();
  179.     incase 29:
  180.     cmd_ledger();
  181.     incase 30:
  182.     chargeCommand(cmd_lend, 2);
  183.     incase 31:
  184.     cmd_help();
  185.     incase 32:
  186.     chargeCommand(cmd_load, 2);
  187.     incase 33:
  188.     chargeCommand(cmd_lookout, 2);
  189.     incase 34:
  190.     chargeCommand(cmd_map, 1);
  191.     incase 35:
  192.     chargeCommand(cmd_mine, 2);
  193.     incase 36:
  194.     chargeCommand(cmd_move, 2);
  195.     incase 37:
  196.     cmd_nation();
  197.     incase 38:
  198.     chargeCommand(cmd_navigate, 2);
  199.     incase 39:
  200.     cmd_newspaper();
  201.     incase 41:
  202.     cmd_power();
  203.     incase 42:
  204.     chargeCommand(cmd_radar, 2);
  205.     incase 43:
  206.     cmd_read();
  207.     incase 44:
  208.     cmd_realm();
  209.     incase 45:
  210.     chargeCommand(cmd_repay, 2);
  211.     incase 46:
  212.     chargeCommand(cmd_route, 1);
  213.     incase 47:
  214.     chargeCommand(cmd_price, 2);
  215.     incase 48:
  216.     chargeCommand(cmd_drop, 2);
  217.     incase 49:
  218.     chargeCommand(cmd_ships, 0);
  219.     incase 50:
  220.     chargeCommand(cmd_spy, 1);
  221.     incase 51:
  222.     cmd_telegram();
  223.     incase 52:
  224.     chargeCommand(cmd_tend, 2);
  225.     incase 53:
  226.     chargeCommand(cmd_torpedo, 2);
  227.     incase 54:
  228.     chargeCommand(cmd_report, 2);
  229.     incase 56:
  230.     chargeCommand(cmd_unload, 2);
  231.     incase 57:
  232.     QuietUpdate := false;
  233.     chargeCommand(cmd_update, 1);
  234.     incase 59:
  235.     cmd_weather();
  236.     incase 60:
  237.     if UsingSerial then
  238.         writeln(Chout; "Enter message to send to system owner:");
  239.         write(Chout; "> ");
  240.         if readLine(&InputBuffer[0], INPUT_LENGTH) then
  241.         writeln();
  242.         writeln(&InputBuffer[0]);
  243.         putPrompt();
  244.         else
  245.         pretend(ioerror(Chin), void);
  246.         fi;
  247.     else
  248.         err("talking to yourself are you?");
  249.     fi;
  250.     incase 61:
  251.     incase 62:
  252.     cmd_help();
  253.     incase 63:
  254.     cmd_examine();
  255.     incase 64:
  256.     cmd_dump();
  257.     incase 65:
  258.     cmd_edit();
  259.     incase 66:
  260.     cmd_translate();
  261.     default:
  262.     writeln(Chout; "Unimplemented Empire command: ", command);
  263.     esac;
  264. corp;
  265.  
  266. /*
  267.  * processCommands - loop, getting commands and parsing them.
  268.  */
  269.  
  270. proc processCommands()void:
  271.     *char COMMAND_LIST =
  272.         /*  2 */ "accept\e"
  273.         /*  3 */ "assault\e"
  274.         /*  4 */ "attack\e"
  275.         /*  5 */ "board\e"
  276.         /*  6 */ "build\e"
  277.         /*  7 */ "bye\e"
  278.         /*  8 */ "census\e"
  279.         /*  9 */ "change\e"
  280.         /* 10 */ "checkpoint\e"
  281.         /* 11 */ "collect\e"
  282.         /* 12 */ "commands\e"
  283.         /* 13 */ "contract\e"
  284.         /* 14 */ "country\e"
  285.         /* 15 */ "fleet\e"
  286.         /* 16 */ "defend\e"
  287.         /* 17 */ "deliver\e"
  288.         /* 18 */ "declare\e"
  289.         /* 19 */ "designate\e"
  290.         /* 20 */ "dissolve\e"
  291.         /* 21 */ "enlist\e"
  292.         /* 22 */ "buy\e"
  293.         /* 23 */ "fire\e"
  294.         /* 24 */ "fly\e"
  295.         /* 25 */ "forecast\e"
  296.         /* 26 */ "grant\e"
  297.         /* 27 */ "headlines\e"
  298.         /* 28 */ "info\e"
  299.         /* 29 */ "ledger\e"
  300.         /* 30 */ "lend\e"
  301.         /* 31 */ "list\e"
  302.         /* 32 */ "load\e"
  303.         /* 33 */ "lookout\e"
  304.         /* 34 */ "map\e"
  305.         /* 35 */ "mine\e"
  306.         /* 36 */ "move\e"
  307.         /* 37 */ "nation\e"
  308.         /* 38 */ "navigate\e"
  309.         /* 39 */ "newspaper\e"
  310.         /* 40 */ "offer\e"
  311.         /* 41 */ "power\e"
  312.         /* 42 */ "radar\e"
  313.         /* 43 */ "read\e"
  314.         /* 44 */ "realm\e"
  315.         /* 45 */ "repay\e"
  316.         /* 46 */ "route\e"
  317.         /* 47 */ "price\e"
  318.         /* 48 */ "drop\e"
  319.         /* 49 */ "ships\e"
  320.         /* 50 */ "spy\e"
  321.         /* 51 */ "telegram\e"
  322.         /* 52 */ "tend\e"
  323.         /* 53 */ "torpedo\e"
  324.         /* 54 */ "report\e"
  325.         /* 55 */ "treaty\e"
  326.         /* 56 */ "unload\e"
  327.         /* 57 */ "update\e"
  328.         /* 58 */ "vote\e"
  329.         /* 59 */ "weather\e"
  330.         /* 60 */ "message\e"
  331.         /* 61 */ "help\e"
  332.         /* 62 */ "?\e"
  333.         /* 63 */ "examine\e"
  334.         /* 64 */ "dump\e"
  335.         /* 65 */ "edit\e"
  336.         /* 66 */ "translate\e";
  337.     *char command, p, fileName;
  338.     file() fyle;
  339.     uint cmd;
  340.     bool quit, redirected, appending;
  341.  
  342.     telegramCheck();
  343.     quit := false;
  344.     while not quit do
  345.     if UsingSerial then
  346.         if WaitForChar(Input(), 0) then
  347.         writeln(Chout; "Activity on master keyboard - please wait.");
  348.         readln(&InputBuffer[0]);
  349.         if CharsEqual(&InputBuffer[0], "QUIT") then
  350.             LeaveGame := true;
  351.             writeln("Quit message sent to user.");
  352.             writeln(Chout;);
  353.             writeln(Chout;);
  354.             writeln(Chout;
  355.             "System owner requires system - please finish up.");
  356.             writeln(Chout;);
  357.             writeln(Chout;);
  358.         elif CharsEqual(&InputBuffer[0], "play") then
  359.             PlayConsole := true;
  360.             writeln("play request recorded - hang tough!!");
  361.         elif CharsEqual(&InputBuffer[0], "message") or
  362.             CharsEqual(&InputBuffer[0], "mess") then
  363.             writeln(Chout; "Message from system owner...");
  364.             write("> ");
  365.             readln(&InputBuffer[0]);
  366.             writeln(Chout; &InputBuffer[0]);
  367.         elif CharsEqual(&InputBuffer[0], "bump") then
  368.             ThisCountry*.c_timer := ThisCountry*.c_timer + 1;
  369.         elif InputBuffer[0] ~= '\e' then
  370.             writeln("Unknown command - only 'QUIT', 'play', 'message'"
  371.                 " and 'bump' known.");
  372.         fi;
  373.         putPrompt();
  374.         fi;
  375.         if serialHungup() then
  376.         quit := true;
  377.         fi;
  378.     fi;
  379.     if not quit then
  380.         write(Chout; '[', ThisCountry*.c_btu, ':',
  381.             ThisCountry*.c_timer, "] Command: ");
  382.         if not readLine(&InputBuffer[0], INPUT_LENGTH) then
  383.         quit := true;
  384.         else
  385.         InputPtr := &InputBuffer[0];
  386.         skipBlanks();
  387.         command := InputPtr;
  388.         if command* ~= '\e' then
  389.             skipWord();
  390.             p := InputPtr;
  391.             skipBlanks();
  392.             p* := '\e';
  393.             redirected := false;
  394.             if InputPtr* = '>' then
  395.             InputPtr := InputPtr + 1;
  396.             redirected := true;
  397.             if InputPtr* = '>' then
  398.                 InputPtr := InputPtr + 1;
  399.                 appending := true;
  400.             fi;
  401.             skipBlanks();
  402.             if InputPtr* = '\e' then
  403.                 err("no output file name - redirection ignored");
  404.                 redirected := false;
  405.             else
  406.                 fileName := InputPtr;
  407.                 skipWord();
  408.                 p := InputPtr;
  409.                 skipBlanks();
  410.                 p* := '\e';
  411.                 if UsingSerial then
  412.                 err("redirection disabled for remote users");
  413.                 redirected := false;
  414.                 elif appending then
  415.                 if open(Chout, fyle, fileName) then
  416.                     pretend(TextAppend(Chout), void);
  417.                 else
  418.                     pretend(FileCreate(fileName), void);
  419.                     if not open(Chout, fyle, fileName) then
  420.                     err("can't open redirection file");
  421.                     redirected := false;
  422.                     fi;
  423.                 fi;
  424.                 else
  425.                 pretend(FileDestroy(fileName), void);
  426.                 pretend(FileCreate(fileName), void);
  427.                 if not open(Chout, fyle, fileName) then
  428.                     err("can't open redirection file");
  429.                     redirected := false;
  430.                 fi;
  431.                 fi;
  432.             fi;
  433.             fi;
  434.             QuietUpdate := true;
  435.             VerboseUpdate := false;
  436.             ContractEarnings := 0;
  437.             InterestEarnings := 0;
  438.             ImprovementCost := 0;
  439.             MilitaryCost := 0;
  440.             UtilitiesCost := 0;
  441.             cmd := lookupCommand(COMMAND_LIST, command);
  442.             if cmd = 0 then
  443.             writeln(Chout; "Unknown Empire command: ", command);
  444.             elif cmd = 1 then
  445.             writeln(Chout; "Ambiguous Empire command: ", command);
  446.             elif cmd = 7 then
  447.             /* bye */
  448.             quit := true;
  449.             else
  450.             doCommand(cmd, command);
  451.             fi;
  452.             if ContractEarnings ~= 0 then
  453.             writeln(Chout; "You earned $", ContractEarnings,
  454.                 " from contracted production.");
  455.             fi;
  456.             if InterestEarnings ~= 0 then
  457.             writeln(Chout; "You earned $", InterestEarnings,
  458.                 " interest from bank deposits.");
  459.             fi;
  460.             if ImprovementCost ~= 0 then
  461.             writeln(Chout; "You paid $", ImprovementCost,
  462.                 " for sector improvements.");
  463.             fi;
  464.             if MilitaryCost ~= 0 then
  465.             writeln(Chout; "You paid $", MilitaryCost,
  466.                 " for military supplies.");
  467.             fi;
  468.             if UtilitiesCost ~= 0 then
  469.             writeln(Chout;
  470.                 "You paid $", UtilitiesCost, " for utilites.");
  471.             fi;
  472.             if redirected then
  473.             close(Chout);
  474.             open(Chout);
  475.             fi;
  476.         fi;
  477.         if updateTimer() then
  478.             /* user's timer has expired! Log him out! */
  479.             writeln(Chout; "You've run out of time! Logging out!");
  480.             quit := true;
  481.         fi;
  482.         fi;
  483.     fi;
  484.     od;
  485. corp;
  486.